Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC][IR] Initial stab at std::string->String upgrade #5438

Merged
merged 1 commit into from
Apr 30, 2020

Conversation

tqchen
Copy link
Member

@tqchen tqchen commented Apr 24, 2020

This PR is an example of String Update with backward compact(see json_compact.py)

@tqchen
Copy link
Member Author

tqchen commented Apr 24, 2020

cc @jroesch @icemelon9

@tqchen tqchen changed the title [IR] Initial stab at std::string->String upgrade [POC][IR] Initial stab at std::string->String upgrade Apr 24, 2020
def _update_from_std_str(key):
def _convert(item, nodes):
str_val = item["attrs"][key]
jdata = json.loads(tvm.ir.save_json(tvm.runtime.String(str_val)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we bring the serialization of tvm:String out of save_json?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a bit about what do you mean? Right now all tvm objects are serialized through save_json, what we are doing here is to get that particular entry and append to the end of the nodes.

@tqchen
Copy link
Member Author

tqchen commented Apr 24, 2020

@jroesch @zhiics
wrt to the String serialization. Right now String is serialized as an normal object. So if the content of String is printable, it will show up as

{type_key: "runtime.String", repr_str: "mystring"}

If the content of the string is not printable, then it will show up as

{type_key: "runtime.String", repr_b64: "base64encoding"}

So the new IR entry will look like (note that the name field actually stores the index to the node table

[
  {"type_key": "TypeVar", "attrs" : { "name": "2" }},
  {type_key: "runtime.String", repr_str: "myname"}
]

This mechanism is baked into json serialization so it is a bit hard to move out. Of course we could also say that String should mostly be printable, and use a special serialization(e.g. just print as str when it is an old str attribute) Thet is a special case though and makes the json serialization harder to work with when directly serialize a String object itself.

@zhiics
Copy link
Member

zhiics commented Apr 24, 2020

@tqchen ahh, I see. I was thinking if it is necessary to have some stuff like Load/Save for tvm::String separately, so that we don't need to put them under serialization.cc. Looks it is not really needed. Thanks.

@tqchen tqchen merged commit 3aa103e into apache:master Apr 30, 2020
@tqchen tqchen deleted the str branch May 14, 2020 15:11
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 9, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Jun 18, 2020
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants